using UnityEngine;
using UnityEngine.UI;

namespace HEFramework
{
    /// <summary>
    ///
    /// UI精灵行为基类
    /// 
    /// ----------------------------------------
    /// 作者 hep
    /// 创建时间：2023-02-17 19:27:49
    /// ----------------------------------------
    /// </summary>
    [RequireComponent(typeof(Image))]
    public class UIImageBehaviourBase : MonoBehaviour, IUIImageBehaviour
    {
        private Image image;

        private Color color;


        public Image Image => image;

        public void Awake()
        {
            if (image == null)
            {
                image = transform.GetComponent<Image>();
            }
        }

        public Transform GetTransform()
        {
            return image.transform;
        }

        /// <summary>
        /// 返回对象
        /// </summary>
        /// <returns></returns>
        public GameObject GetGameObject()
        {
            return image.gameObject;
        }

        public IUIImageBehaviour SetImage(Sprite _sprite)
        {
            image.sprite = _sprite;
            return this;
        }

        public IUIImageBehaviour SetColor(int _r, int _g, int _b, int _a)
        {
            color.r = _r;
            color.g = _g;
            color.b = _b;
            color.a = _a;
            image.color = color;
            return this;
        }

        public RectTransform GetRectTransform()
        {
            return image.rectTransform;
        }
    }
}